package com.learning.javaweb_springboot_test.controller;


import com.learning.javaweb_springboot_test.entity.Student;
import com.learning.javaweb_springboot_test.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


//Controller层，与前端接触，模仿前端请求，向前端获取或提交数据


@RestController()
public class StudentController {

    @Autowired
    private StudentService studentService; // 声明一个StudentService的对象


    // 根据ID查询
    @GetMapping("/students/{id}")
    public Student queryStudentById(@PathVariable Integer id) {
        return studentService.queryStudentById(id);
    }

    // 插入学生
    @PostMapping("/students")
    public void addStudent(@RequestBody Student student) {
        studentService.addStudent(student);
    }

}
